﻿using System.Linq;
using System.Text;
using OrderingPlatform.Model;

namespace OrderingPlatform.WebUI.App_Start
{
    public class Common
    {
        public static CallBackModel GetModelStateErrorResult(System.Web.Mvc.ModelStateDictionary modelState)
        {
            var list = modelState.Values.Where(a => a.Errors.Any());
            var errorList = new StringBuilder();
            foreach (var item in list)
            {
                errorList.AppendFormat("{0}</br>", item.Errors.Select(a => a.ErrorMessage).FirstOrDefault());
            }
            var result = new OrderingPlatform.Model.CallBackModel
            {
                State = 0,
                Message = errorList.ToString()
            };
            return result;
        }
    }
}